home *** CD-ROM | disk | FTP | other *** search
/ PCNet 1998 May / PCnet Mayıs 1998.iso / Multimed / Program / A_Trial.exe / data.z / JMxTimer.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-12-04  |  1.3 KB  |  102 lines

  1. public class JMxTimer implements Runnable {
  2.    public static final int MX_TMTHD_IDLE = 0;
  3.    public static final int MX_TMTHD_START = 1;
  4.    public static final int MX_TMTHD_STARTED = 2;
  5.    public static final int MX_TMTHD_STOP = 3;
  6.    public static final int MX_TMTHD_KILL = 4;
  7.    public static final int MX_TMTHD_KILLED = 5;
  8.    public JMxTimeable m_Owner;
  9.    public Thread m_TimerThread;
  10.    private long m_Interval;
  11.    public int m_State;
  12.  
  13.    public synchronized void Kill() {
  14.       if (this.m_State != 4) {
  15.          this.m_State = 4;
  16.          this.notifyAll();
  17.       }
  18.  
  19.    }
  20.  
  21.    public synchronized void Stop() {
  22.       switch (this.m_State) {
  23.          case 1:
  24.          case 2:
  25.             this.m_State = 3;
  26.             this.notifyAll();
  27.             return;
  28.          default:
  29.       }
  30.    }
  31.  
  32.    public JMxTimer(JMxTimeable var1) {
  33.       this.m_Owner = var1;
  34.       this.m_TimerThread = new Thread(this);
  35.       this.m_TimerThread.start();
  36.    }
  37.  
  38.    public void run() {
  39.       synchronized(this){}
  40.  
  41.       try {
  42.          boolean var1 = false;
  43.  
  44.          while(true) {
  45.             var1 = false;
  46.             switch (this.m_State) {
  47.                case 0:
  48.                   var1 = true;
  49.                   break;
  50.                case 1:
  51.                   this.m_State = 2;
  52.  
  53.                   try {
  54.                      this.wait(this.m_Interval);
  55.                   } catch (InterruptedException var10) {
  56.                   }
  57.                   break;
  58.                case 2:
  59.                   this.m_Owner.tick(this);
  60.                   this.m_State = 0;
  61.                   var1 = true;
  62.                   break;
  63.                case 3:
  64.                   this.m_State = 0;
  65.                   var1 = true;
  66.                   break;
  67.                case 4:
  68.                   this.m_State = 5;
  69.                   return;
  70.             }
  71.  
  72.             if (var1) {
  73.                try {
  74.                   this.wait();
  75.                } catch (InterruptedException var9) {
  76.                   ((Throwable)var9).printStackTrace();
  77.                }
  78.             }
  79.          }
  80.       } catch (Throwable var11) {
  81.          throw var11;
  82.       }
  83.    }
  84.  
  85.    public synchronized boolean Start(long var1) {
  86.       switch (this.m_State) {
  87.          case 0:
  88.          case 3:
  89.             this.m_Interval = var1;
  90.             this.m_State = 1;
  91.             this.notifyAll();
  92.             return true;
  93.          case 1:
  94.             this.notifyAll();
  95.          case 2:
  96.          case 4:
  97.          default:
  98.             return false;
  99.       }
  100.    }
  101. }
  102.